package main

import (
	"fmt"
	"regexp"
)

//两种字符串表示方式 转义，非转义
const text = "My email is luizsuper@163.com.cn"
const text1 = `My email is ll@163.com
               email2 is cuiyao@16.com email3 is bieshale@qq.com
`
const group_regex = `([a-zA-Z0-9]+)@([a-zA-Z0-9]+)(\.[a-zA-Z0-9]+)`

func main() {
	//如果不想让字符串转义就用··
	//compile:= regexp.MustCompile(`.+@.+\.com`)
	compiles := regexp.MustCompile("[a-zA-Z0-9]+@[a-zA-Z0-9\\.]+\\.[a-zA-Z0-9]+")
	gourp_compiles := regexp.MustCompile(group_regex)
	findString := compiles.FindString(text)
	allString := compiles.FindAllString(text1, -1)
	fmt.Printf("the type of find string is %T, value is %v \n", findString, findString)
	fmt.Printf("the type of findall is %T values are %v \n", allString, allString)
	fmt.Println("__________________________________")
	group_str := gourp_compiles.FindAllStringSubmatch(text1, -1)
	for _, m := range group_str {
		fmt.Println(m)
	}
	fmt.Println("__________________________________")
	submatch := gourp_compiles.FindStringSubmatch(text1)
	for _, m := range submatch {
		fmt.Println(m)
	}
}
